package com.meilai.project.controller.web.administration.goods;

import com.meilai.project.dto.CommonResult;
import com.meilai.project.dto.administration.goods.GoodsStorageManageDTO;
import com.meilai.project.dto.base.ApiResult;
import com.meilai.project.entity.administration.goods.GoodsType;
import com.meilai.project.service.administration.goods.GoodsStorageManageService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "物品库存管理", tags = {"库存管理"})
@RestController
@RequestMapping("api/web/goods_storage_manage")
public class GoodsStorageManageController {

    @Autowired
    private GoodsStorageManageService service;


    @GetMapping("list")
    @ApiOperation(value = "库存列表")
    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"),
            @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"),
            @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"),
            @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"),
            @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
    @ResponseBody
    public CommonResult list(@RequestParam(name = "page", defaultValue = "1") Integer page,
                             @RequestParam(name = "page_size", defaultValue = "10") Integer page_size,
                             @ApiParam(name = "goods_type_id", value = "物品类型", required = false)
                             @RequestParam(value = "goods_type_id", required = false) Long goods_type_id,
                             @ApiParam(name = "storage_number_min", value = "库存最小值", required = false)
                             @RequestParam(value = "storage_number_min", required = false) Long storage_number_min,
                             @ApiParam(name = "storage_number_max", value = "库存最大值", required = false)
                             @RequestParam(value = "storage_number_max", required = false) Long storage_number_max) {
        GoodsStorageManageDTO searchDTO = new GoodsStorageManageDTO();
        searchDTO.setGoods_type_id(goods_type_id);
        searchDTO.setStorage_number_min(storage_number_min);
        searchDTO.setStorage_number_max(storage_number_max);
        return new CommonResult().success(service.selectPageList(page, page_size, searchDTO));
    }

    @GetMapping("storage_list")
    @ApiOperation("获取库存列表")
    public ApiResult<List<GoodsType>> storageList() {
        return ApiResult.ok(service.storageList());
    }

//    @PostMapping("edit")
//    @ApiOperation(value = "修改")
//    @ApiResponses({@ApiResponse(code = CommonResult.SUCCESS, message = "操作成功"),
//            @ApiResponse(code = CommonResult.VALIDATE_FAILED, message = "参数校验失败"),
//            @ApiResponse(code = CommonResult.UNAUTHORIZED, message = "未认证"),
//            @ApiResponse(code = CommonResult.FORBIDDEN, message = "未授权"),
//            @ApiResponse(code = CommonResult.FAILED, message = "操作失败")})
//    @ResponseBody
//    public CommonResult edit(@RequestBody GoodsStorageManageDTO dto) {
//        if (service.editOneById(dto)) {
//            return new CommonResult().success("修改成功");
//        }
//        return new CommonResult().failed("修改失败");
//    }

}
